<?php require_once '../global.php';

function king_def(){
	global $king;
	$a=kc_get('pc');
	if(!empty($a)){
	$pc=' and nshow = 1';
	$url='&pc=1';
	}else{
	$pc=' and nshow = 0';
	$url='';
	}






	$king->access('keywords');

$_cmd=array(
		'delete'=>$king->lang->get('system/common/del'),
	);
	$brow_link=($king->config('rewritetag') ? "../tag" : "../index.php/tag").$king->config('rewriteline');

	$manage ="'<a target=\"_blank\" href=\"{$brow_link}'+(K[1])+'".$king->config('rewriteend')."\">'+$.kc_icon('h7','".$king->lang->get('system/common/brow')."')+'</a>'";
	$manage.="+'<a href=\"../portal/manage.tag.php?action=edt&kid='+K[0]+'\">'+$.kc_icon('k5','".$king->lang->get('system/common/edit')."')+'</a>'";
	$manage.="+'<a class=\"k_ajax\" rel=\"{CMD:\'delete\',list:'+K[0]+'}\">'+$.kc_icon('l5','".$king->lang->get('system/common/del')."')+'</a>'";


	$_js=array(
		"$.kc_list(K[0],K[1],'../portal/manage.tag.php?action=edt&kid='+K[0])",
		$manage,
		"'<i>'+ishow('manage.php',K[0],K[2])+'</i>'",//显示
		"K[3]",

	);
	$s=$king->openList($_cmd,'',$_js,$king->db->pagelist('manage_tag.php?pid=PID&rn=RN'.$url,$king->db->getRows_number('%s_tag','kid!=0'.$pc)));

	$_sql="select kid,ktag,nshow,kcolor,nsize,isbold,iscommend,ndate from %s_tag where kid!=0 ".$pc." order by nshow asc,kid desc";
	if(!$res=$king->db->getRows($_sql,1)) $res=array();

$s.="function ishow(url,id,is){var I1,ico;is?ico='n1':ico='n2';";
	$s.="I1='<a id=\"nshow_'+id+'\" class=\"k_ajax\" rel=\"{CMD:\'show\',value:'+ (1-is) +',ID:\'nshow_'+id+'\',list:'+id+',IS:2}\" >'+$.kc_icon(ico,(is?'".$king->lang->get('keywords/list/unshow')."':'".$king->lang->get('keywords/list/show')."'))+'</a>';return I1;};";
	
	$s.="ll('".$king->lang->get('keywords/list/ktag')."',
		'".$king->lang->get('keywords/list/show')."',
		'".$king->lang->get('keywords/list/show')."',
	    '".$king->lang->get('keywords/list/date')."',1);";


	foreach($res as $rs){
		$s.="ll({$rs['kid']},
		    '".addslashes(htmlspecialchars($rs['ktag']))."',
			 ".$rs['nshow'].",
		    '".kc_formatdate($rs['ndate'])."',0);";
	}











	$s.=$king->closeList();

	list($left,$right)=inc_menu();

	$king->skin->output($king->lang->get('keywords/title/center'),$left,'',$s);

}


/**
菜单调用
*/
function inc_menu(){
	global $king;
	$left=array(
		'0'=>array(
			'href'=>'manage.php',
			'ico'=>'p7',
			'title'=>$king->lang->get('keywords/list/title'),
			),
		'1'=>array(
			'href'=>'manage_tag.php',
			'ico'=>'p7',
			'title'=>$king->lang->get('keywords/list/ktag'),
			),
		'2'=>array(
			'href'=>'manage_tag.php',
			'ico'=>'p7',
			'title'=>'正常',
			),
		'3'=>array(
			'href'=>'manage_tag.php?pid=1&rn=20&pc=1',
			'ico'=>'p7',
			'title'=>'过滤',
			),
		'edt'=>array(
			'href'=>'javascript:;',
			'ico'=>'c2',
			'title'=>'添加分词',
			'rel'=>"{CMD:'fc',METHOD:'GET',URL:'./index.php'}",
			'class'=>"k_ajax",
		),
	);
	

	return array($left,array());
}





//删除留言
function king_ajax_delete(){
	global $king;
	$king->access('keywords_delete');
	$list=kc_getlist();
	$king->db->query("delete from %s_tag where kid in ($list)");
	kc_ajax('OK',"<p class=\"k_ok\">".$king->lang->get('system/ok/delete')."</p>",1);
}


//显示隐藏
function king_ajax_show(){
	global $king;

	$king->access('keywords_edt');
	$kid=kc_get('list',2,1);
	$value=kc_get('value',2,1);
	$king->db->query("update %s_tag set nshow=$value where kid=$kid;");



	if($value=='1'){
		
						$keyid=$king->db->getRows_one("select ktag from %s_tag where kid='".$kid."'");
	
						$king->db->query("delete from %s_key_tag_id where tagid ='".$kid."'");
					
						$king->db->query("delete from %s_key where ktitle like '%".$keyid['ktag']."%'");	
	}


	$value ? $ico='n1':$ico='n2';
	kc_ajax('',
		kc_icon($ico,($value?$king->lang->get('keywords/list/unshow'):$king->lang->get('keywords/list/show'))),
		0,
		"$('#nshow_{$kid}').attr('rel','{CMD:\'show\',value:".(1-$value).",ID:\'nshow_{$kid}\',list:\'$kid\',IS:2}')");
}



 //上移下移
//king_ajax_updown
function king_ajax_updown(){
	global $king;
	$king->access('portal_tag_edt');

	$kid=kc_get('kid',2,1);

	$king->db->updown('%s_tag',$kid);
}

function king_ajax_commend(){
	global $king;
	$king->access('portal_tag_edt');
	$kid=kc_get('kid',2,1);
	$is=kc_get('is',2,1);
	$ico= $is ? 'n1':'n2';

	$king->db->update('%s_tag',array('iscommend'=>$is),"kid=$kid");

	kc_ajax('',kc_icon($ico),'',"$('#commend_{$kid}').attr('rel','{CMD:\'commend\',ID:\'commend_{$kid}\',is:".(1-$is).",kid:{$kid},IS:2}')");

//{CMD:\commend\',is:'+is+',ID:\'commend_'+id+'\',kid:'+id+',IS:2}
}

?>